package com.dhgate.amazonCraw.pipline;

import java.util.Date;
import java.util.List;

import com.dhgate.amazon.dao.AmazonDao;
import com.dhgate.amazonCraw.model.AmazonCategoryAttModel;
import com.dhgate.amazonCraw.po.AmazonCategoryAtt;

import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

public class AmazonPipeline implements Pipeline{
	AmazonDao amazonDao = new AmazonDao(); 
	public void process(ResultItems resultItems, Task task) {
		
		List<AmazonCategoryAttModel> amazonCategoryAttModels = resultItems.get("amazonCategoryAttModels");
		if(amazonCategoryAttModels!=null&&amazonCategoryAttModels.size()>0){
			for(AmazonCategoryAttModel amazonCategoryAttModel : amazonCategoryAttModels){
				save(amazonCategoryAttModel);
				//System.out.println(amazonCategoryAttModel.toString());
			}
		}
	}
	public void save(AmazonCategoryAttModel amazonCategoryAttModel){
		AmazonCategoryAtt amazonCategoryAtt = new AmazonCategoryAtt(); 
		amazonCategoryAtt.setPrimaryCategory(amazonCategoryAttModel.getPrimaryCategory());
		amazonCategoryAtt.setSecondaryCategory(amazonCategoryAttModel.getSecondaryCategory());
		amazonCategoryAtt.setThirdCategory(amazonCategoryAttModel.getThirdCategory());
		amazonCategoryAtt.setFourthCategory(amazonCategoryAttModel.getFourthCategory());
		amazonCategoryAtt.setFifthCategory(amazonCategoryAttModel.getFifthCategory());
		amazonCategoryAtt.setSixthCategory(amazonCategoryAttModel.getSixthCategory());
		amazonCategoryAtt.setSeventhCategory(amazonCategoryAttModel.getSeventhCategory());
		amazonCategoryAtt.setEighthCategory(amazonCategoryAttModel.getEighthCategory());
		amazonCategoryAtt.setNinthCategory(amazonCategoryAttModel.getNinthCategory());
		amazonCategoryAtt.setTenCategory(amazonCategoryAttModel.getTenCategory());
		amazonCategoryAtt.setBottomUrl(amazonCategoryAttModel.getBottomUrl());
		amazonCategoryAtt.setAttName(amazonCategoryAttModel.getAttName());
		amazonCategoryAtt.setAttValue(amazonCategoryAttModel.getAttValue());
		amazonCategoryAtt.setCreateTime(new Date());
		amazonDao.addInfo(amazonCategoryAtt);
	}
}
